<template>
  <div>
    <h1>未分班的学生：</h1>
    {{ userid }}
    <table align="center">
      <tr>
        <td>学生姓名</td>
        <td>操作</td>
      </tr>
      <tr v-for="i in adds">
        <td>{{ i.name }}</td>
        <td>
          <button @click="add_stu(i.id)">加入该班级</button>
        </td>
      </tr>
    </table>
  </div>
</template>

<script>
export default {
  name: "no_stu",
  data() {
    return {
      userid: localStorage.getItem('userid'),
      adds: []
    }
  },
  methods: {
    get_stu() {
      this.$axios.get('users/StusAPI/')
        .then(res => {
          this.adds = res.data.list
        })
    },
    add_stu(id) {
      this.$axios.put('users/StusAPI/?id=' + id + '&usersid=' + this.userid)
        .then(res => {
          if (res.data.code == 200) {
            alert('加入成功')
            this.get_stu()
          } else {
            alert('加入失败')
          }
        })
    }
  },
  mounted() {
    this.get_stu()
  }
}
</script>

<style scoped>

</style>
